﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Liang.Device.Camera.Dll
{
    /// <summary>
    /// 港宇摄像头DLL
    /// </summary>
    class CamyuDll
    {
        /// <summary>
        /// 初始化摄像头SDK
        /// </summary>
        /// <returns></returns>
        [DllImport("KsCamera_Camyu.dll")]
        public static extern Boolean KsCamera_Camyu_Init();

        /// <summary>
        /// 注销SDK
        /// </summary>
        [DllImport("KsCamera_Camyu.dll")]
        public static extern void KsCamera_Camyu_Cleanup();

        /// <summary>
        /// 登陆
        /// </summary>
        /// <param name="szIPAddr">摄像头IP地址</param>
        /// <param name="nControlPort">控制端口号</param>
        /// <param name="nTransPort">传输端口号</param>
        /// <returns></returns>
        [DllImport("KsCamera_Camyu.dll")]
        public static extern IntPtr KsCamera_Camyu_Login(string szIPAddr, ushort nControlPort = 8886, ushort nTransPort = 8888);

        /// <summary>
        /// 登出
        /// </summary>
        /// <param name="hCamera">设备句柄</param>
        [DllImport("KsCamera_Camyu.dll")]
        public static extern void KsCamera_Camyu_Logout(IntPtr hCamera);

        /// <summary>
        /// 实时播放
        /// </summary>
        /// <param name="hCamera"></param>
        /// <param name="hPlayWnd"></param>
        /// <returns></returns>
        [DllImport("KsCamera_Camyu.dll")]
        public static extern Boolean KsCamera_Camyu_Play(IntPtr hCamera, IntPtr hPlayWnd);

        /// <summary>
        /// 停止播放
        /// </summary>
        /// <param name="hCamera"></param>
        /// <returns></returns>
        [DllImport("KsCamera_Camyu.dll")]
        public static extern void KsCamera_Camyu_Stop(IntPtr hCamera);

        /// <summary>
        /// 抓拍
        /// </summary>
        /// <param name="hCamera"></param>
        /// <param name="szImageFile"></param>
        /// <returns></returns>
        [DllImport("KsCamera_Camyu.dll")]
        public static extern Boolean KsCamera_Camyu_Capture(IntPtr hCamera, string szImageFile);

        /// <summary>
        /// 触发抓拍（由抓拍服务器接收）
        /// </summary>
        /// <param name="hCamera"></param>
        /// <param name="strImageFile"></param>
        /// <param name="nFlashChannel"></param>
        [DllImport("KsCamera_Camyu.dll")]
        public static extern void KsCamera_Camyu_TriggerCaptureAsync(IntPtr hCamera, string strImageFile, ushort nFlashChannel);

        /// <summary>
        /// 抓拍监听服务
        /// </summary>
        /// <param name="nPort"></param>
        [DllImport("KsCamera_Camyu.dll")]
        public static extern Boolean KsCamera_Camyu_OpenSnapServer(ushort nPort = 9999);

        /// <summary>
        /// 关闭抓拍监听服务
        /// </summary>
        [DllImport("KsCamera_Camyu.dll")]
        public static extern void KsCamera_Camyu_CloseSnapServer();

        /// <summary>
        /// 校时
        /// </summary>
        /// <param name="hCamera"></param>
        /// <param name="nYear"></param>
        /// <param name="nMonth"></param>
        /// <param name="nDay"></param>
        /// <param name="nHour"></param>
        /// <param name="nMinute"></param>
        /// <param name="nSecond"></param>
        [DllImport("KsCamera_Camyu.dll")]
        public static extern void KsCamera_Camyu_Timing(IntPtr hCamera, int nYear, int nMonth, int nDay, int nHour, int nMinute, int nSecond);
    }
}
